package leetcode_2501_2600;

import java.util.PriorityQueue;

public class LeeCode_2558 {
    public static void main(String[] args) {
        System.out.println(pickGifts(new int[]{25, 64, 9, 4, 100}, 4));
    }
    private static long pickGifts(int[] gifts, int k) {
        PriorityQueue<Integer> queue = new PriorityQueue<>((o1, o2) -> o2 - o1);
        for (int gift : gifts) {
            queue.add(gift);
        }
        for (int i = 0; i < k; i++) {
            Integer poll = queue.poll();
            double pow = Math.sqrt(poll);
            double floor = Math.floor(pow);
            int floor1 = (int) floor;
            queue.add(floor1);
        }
        long ans = 0;
        while (!queue.isEmpty()){
            ans += queue.poll();
        }
        return ans;
    }
}
